<?php
require_once($application_folder."/controllers/navigator.php");
class DirectoryMedia extends Navigator{

    function __construct(){
        parent::__construct();
        
        /************************************************************
        * CHECK LOGIN
        *************************************************************/
        if(!$this->session->userdata('logged_in')){
            redirect(base_url());
        }
        
        $this->load->model('articlem','art');
        $this->load->helper('date');
    }

    function index(){
        $this->preview();
    }

    function preview(){
        
        /************************************************************
        * GET DIRECTORY TABLE
        *************************************************************/


        $this->db->where($array = array('parent !=' => 0));
        $data['directoryMedia'] = $this->db->get('directory')->result_array();

        $this->core_cms('directoryMedia', $data, 'preview');                                  
    }

    function newform(){
        
        /************************************************************
        * GET DIRECTORY TABLE
        *************************************************************/
        $this->db->where($array = array('parent !=' => 0));  
        $data['directoryMedia'] = $this->db->get('directory')->result_array();

        /*if(isset($_GET['id'])){
        $data['columnname'] = $this->db->get_where('subcolumn', array('id' => $_GET['subcolumnid']))->result_array();    
        }   */


        $this->core_cms('directoryMedia', $data, 'new_edit_form');                                  
    }

    function editform(){
        
        /************************************************************
        * GET DIRECTORY TABLE 
        *************************************************************/         
        
        $this->db->where($array = array('parent !=' => 0)); 
        $data['directoryMedia'] = $this->db->get('directory')->result_array();
        
        /************************************************************
        * GET DIRECTORY WITH ID TABLE DATA
        *************************************************************/         
        
        $this->db->where('id',$_GET['id']);    
        $data['directoryData'] = $this->db->get('directory')->result_array();

        $this->core_cms('directoryMedia', $data, 'new_edit_form');                                  
    }

    function edit_insert(){
        
        switch ($_POST['appmode']){

            case 'insert':
                $this->db->insert('directory', array('name' => $_POST['name'], 'description' => $_POST['description'], 'parent' => $_POST['parent']));
                echo json_encode(array('action'=> true)); 
                break;

            case 'edit':

                $this->db->where('id', $_POST['id']);
                $this->db->update('directory', array('name' => $_POST['name'], 'description' => $_POST['description'], 'parent' => $_POST['parent']));

                echo json_encode(array('action'=> true));

                break;

        }

    }

    function deleteone(){
        
        $this->db->where('id',$_POST['id']);
        $this->db->delete('directory');
        echo json_encode(array('action'=> true));
    }

}
